package com.hzcx.app.simplechat.ui.friend.adapter;

import android.view.View;
import android.widget.ImageView;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.hzcx.app.simplechat.R;
import com.hzcx.app.simplechat.ui.friend.bean.FriendBean;
import com.hzcx.app.simplechat.ui.friend.bean.FriendCityBean;
import com.hzcx.app.simplechat.util.UserInfoUtil;
import com.hzcx.app.simplechat.util.empty.EmptyUtils;
import com.hzcx.app.simplechat.util.glide.GlideUtils;

import java.util.List;

public class FriendContentAdapter extends BaseQuickAdapter<FriendCityBean, BaseViewHolder> {

    private int tag; // 是否展示checkbox控件

    public FriendContentAdapter(@Nullable List<FriendCityBean> data) {
        super(R.layout.rv_item_friend_content, data);
    }

    public FriendContentAdapter(@Nullable List<FriendCityBean> data, int tag) {
        super(R.layout.rv_item_friend_content, data);
        this.tag = tag;
    }

    @Override
    protected void convert(BaseViewHolder helper, FriendCityBean item) {
        GlideUtils.loadImg(mContext, item.getAvatar(), helper.getView(R.id.iv_head));
        if (EmptyUtils.isNotEmpty(item.getRemarks_name())) {
            helper.setText(R.id.tv_nick_name, item.getRemarks_name());
        } else {
            helper.setText(R.id.tv_nick_name, item.getNickname());
        }

        // 会员才支持查看好友是否在线
        if (UserInfoUtil.getUserIsVip()) {
            helper.setText(R.id.tv_online_state, item.getOnline_time());
        }

        ImageView ivCheckBox = helper.getView(R.id.iv_check_box);
        if (tag == 1) {
            ivCheckBox.setVisibility(View.VISIBLE);
            if (item.isChecked()) {
                ivCheckBox.setImageResource(R.mipmap.ic_icon_check_select);
            } else {
                ivCheckBox.setImageResource(R.mipmap.ic_icon_check_normal);
            }
        } else {
            ivCheckBox.setVisibility(View.GONE);
        }
    }
}
